/*
 * StateManager.cpp
 *
 *  Created on: 15 Nov 2013
 *      Author: axel
 */

#include "StateManager.h"


StateManager::StateManager(void)
{
	currentcode = 0;
	codes = new KeyCode();
}


StateManager::~StateManager(void)
{
}

StateMachine* StateManager::initialiseState() {
	codes->getHashMap()[200000000]->reInit();
	return codes->getHashMap()[200000000];
}

void StateManager::changePlacesBeen(long code, StateMachine* machine) {
	placesbeen[code]=machine;
}

StateMachine* StateManager::getStateValue(long code) {
	return placesbeen[code];
}

StateMachine* StateManager::callStates(long code, long oldcode, StateMachine* oldmachine) {
	StateMachine* machine;

	if (codes->getSpecial().count(code)){
		machine =  placesbeen[currentcode];
	}
	else{

		if (placesbeen.count(code)){
			machine = placesbeen[code];
		}
		else{
			machine = codes->getHashMap()[code];
		}
	}
	currentcode=oldcode;
	changePlacesBeen(oldcode,oldmachine);
	machine->reInit();

	return machine;

	//check if special
	//if true --> we need to trace back to last known pos
	//from and too completly different places

	//search placesbeen
	//we are tracing back to another place

	//else search in codes
	//new place
}
